﻿//Orginal date made: 27th March 2012
//Excerpts taken from, Jon Skeet: http://stackoverflow.com/questions/6151625/should-i-use-a-struct-or-a-class-to-represent-a-lat-lng-coordinate

//Last modified: 17th Apr 2012
//Modifier name: Luke

using System;
using System.Windows;

namespace SharedResources.Model
{
    public struct GeoCoordinate
    {

        //Struct value to represent latitude and longitude
        //Assumptions:
        //longitude == x axis
        //latitude == y axis

        private readonly double _latitude;
        private readonly double _longitude;

        public double Latitude { get { return _latitude; } }
        public double Longitude { get { return _longitude; } }

        private readonly Point _pointData ;
        public Point PointData { get { return _pointData; } }

        public GeoCoordinate(double latitude, double longitude)
        {
            _latitude = latitude;
            _longitude = longitude;
            _pointData = new Point(longitude, latitude);
        }

        ////////////////////Overidden Methods///////////////

        public override string ToString()
        {
            return string.Format("{0},{1}", Latitude, Longitude);
        }

        public override bool Equals(Object other)
        {
            return other is GeoCoordinate && Equals((GeoCoordinate)other);
        }

        public bool Equals(GeoCoordinate other)
        {
            //if the value being checked is has exactly the same latitude and longitude then it must be the same
            //the way to check this is y2-y1 = 0 and x2 - x1 = 0
            //episilon is the closest double that you can get to zero
            return Math.Abs(Latitude - other.Latitude) < double.Epsilon && Math.Abs(Longitude - other.Longitude) < double.Epsilon;
        }

        public override int GetHashCode()
        {
            return Latitude.GetHashCode() ^ Longitude.GetHashCode();
        }

    }
}
